let vm = new Vue({
    el: "#content",
    data: {
        focusList: [],
        totalPage: "", //总页数
        page: 1,       //当前页
    },
    methods: {
        findFocus: function (page) {
            if (this.totalPage == 0) {
                this.totalPage = 1;
            }
            if (page < 1) {
                layer.msg("已经是第一页了");
                return;
            }
            if (page > this.totalPage) {
                layer.msg("已经是最后一页了");
                return;
            }
            axios({
                method: "get",
                url: `/user/findFocusPage/${page}`,
                params: {username: this.username}
            }).then(res => {
                if (res.data.flag) {
                    this.focusList = res.data.data.rows;// 当前页数据
                    this.totalPage = res.data.data.totalPage;//总页数
                    this.page = page;//当前页
                } else {
                    layer.msg(res.data.message);
                }
            });
        },
        detail: function (user) {
            if (user.isSecret == 0) {
                layer.msg("对方设置了私秘！");
                return;
            }
            sessionStorage.setItem("userId", user.id);
            location.href = "/html/user_detail.html";
        },
        focus: function (user,index) {
            axios({
                method: "get",
                url: `/user/focus/${user.id}`
            }).then(res => {
                layer.msg(res.data.message);
                if (res.data.flag) {
                    this.focusList.splice(index, 1);
                    if (this.focusList.length===0){
                        this.findFocus(this.page-1)
                    }
                }
            });
        }
    },
    created: function () {
        this.findFocus(1);
    }

})